package com.situ.springbootscientific.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.springbootscientific.mapper.AuthMapper;
import com.situ.springbootscientific.pojo.Auth;
import com.situ.springbootscientific.pojo.query.AuthQuery;
import com.situ.springbootscientific.pojo.vo.ResearchersVo;
import com.situ.springbootscientific.service.IAuthService;
import com.situ.springbootscientific.utils.PageRusults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthServiceImpl implements IAuthService {
    @Autowired
    private AuthMapper authMapper;
    @Override
    public List<Auth> findAll(Integer role) {
        return authMapper.findAll(role);
    }

    @Override
    public PageRusults list(AuthQuery authQuery) {
        PageHelper.startPage(authQuery.getPage(), authQuery.getLimit());
        //1.查询当前页列表
        List<Auth> authList = authMapper.list(authQuery);
        //2.用一个小插件查询总数量
        PageInfo pageInfo = new PageInfo(authList);
        int total = (int) pageInfo.getTotal();
        return new PageRusults(0,"",total,authList);
    }

    @Override
    public List<Auth> selectByRole(Integer role) {
        return authMapper.selectByRole(role);
    }
}
